package com.atguigu.crowd.util;/*
 *ClassNmae:ResultEntity
 *Package:com.atguigu.crowd.util
 *Description:
 *@Date:2020/6/15 9:36
 *@Author:1519524541@qq.com
 */
//统一AJAX请求返回的结果
public class ResultEntity<T> {
    private static final String SUCCESS = "SUCCESS";
    private static final String FAILED = "FAILED";
//    封装处理结果
    private String result;

    //请求的错误消息
    private String message;

    //返回的数据
    private T data;

    public static <Type> ResultEntity<Type> successWithoutData(){
        return new ResultEntity<Type>(SUCCESS,null,null);
    }

    public static <Type> ResultEntity<Type> successWithoutData(Type data){
        return new ResultEntity<Type>(SUCCESS,null,data);
    }

    public static <Type> ResultEntity<Type> failed(String message){
        return new ResultEntity<Type>(FAILED,message,null);
    }
    public ResultEntity() {
    }

    public ResultEntity(String result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getResult() {
        return result;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    @Override
    public String toString() {
        return "ResultEntity{" +
                "result='" + result + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
